using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System;

namespace DesignPattern.Creational.Prototype
{
    [Serializable]
    public class Student : ICloneable
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public Class Class { get; set; }

        public object Clone()
        {
            return this.MemberwiseClone();
        }

        public Student DeepClone()
        {
            using var stream = new MemoryStream();
            var formatter = new BinaryFormatter();
            formatter.Serialize(stream, this);

            stream.Seek(0, SeekOrigin.Begin);

            return formatter.Deserialize(stream) as Student;
        }

        public Student ShallowClone()
        {
            return Clone() as Student;
        }
    }
}